package cate.game.play.skill.passive.fairy;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.proce.turn.AppendTurn;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 效果1：回合结束时对敌方全体进行天威审判，50%概率使其受到一次天威伤害（攻击45%+天威标记数*15%）并增加1层天威标记，天威伤害上限为120%标记无法被净化
 * 效果2：“帝印决”系数+10%，对【震伤】目标额外伤害提升10%，若技能释放后附加的【震伤】目标小于3时，该回合【天威】伤害提升80%（法连附加的震伤不做计数）
 */
public class 帝都烤鸭灵器PH extends PassiveHandler {


	private int 追加技能;

	private String 技能标签;

	private String buff标签;

	private int 数量;

	private double 提升系数;

	//追加技能=？？&技能标签=帝印决&buff标签=震伤&数量=3&提升系数=8000
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		追加技能 = args.getInt("追加技能", 0);
		技能标签 = args.get("技能标签");
		buff标签 = args.get("buff标签");
		数量 = args.getInt("数量", 0);
		提升系数 = args.getDouble("提升系数", 0d);
	}

	private boolean addDamage;

	@Override
	public void onRoundEnd(ActionCtx action) {
		Skill appendSkill = action.getCfg().skill.buildById(skill.owner, 追加技能);
		if (appendSkill == null) {
			return;
		}
		if (addDamage) {
			appendSkill.param.addHpCfgByCoeff(提升系数);
			addDamage = false;
		}
		action.getRound().addAppendTurn(new AppendTurn(skill.owner, appendSkill));
	}


	private int buffNum;

	@Override
	public void beforeOwnerMove(MoveCtx move, TimeActionCtx action) {
		if(move.isAppend()){
			return;
		}
		if(!move.getSkill().cfg.containTag(技能标签)){
			return;
		}
		buffNum = countBuff(move);
	}

	@Override
	public void onOwnerMoveDone(MoveCtx move, TimeActionCtx action) {
		if (move.isAppend()) {
			return;
		}
		if (!move.getSkill().cfg.containTag(技能标签)) {
			return;
		}
		int curBuffNum = countBuff(move);
		if (curBuffNum - buffNum < 数量) {
			addDamage = true;
		}
	}

	private int countBuff(MoveCtx move){
		int total = 0;
		for (Fighter fighter : move.getTeamVS().getEnemyTeam(skill.owner.getTeam()).getFightersAlive()) {
			total+=fighter.buff.countBuffByTag(buff标签);
		}
		return total;
	}
}
